<?php
include_once(CONFIG_PATH."/admin-menu.php");
class admin_util_menu{
	/**
	 * 生成左侧menu
	 *
	 * @param [] $data
	 * @param string $str
	 * @return string
	 */
	public static function gen($data, $str='', $sub=0){
		$ret = $str.'<ul class="left-nav ">';
		
		foreach($data as $name=>$param){
			if(count($param)>1){
				$sub = true;
			}else{
				$sub = false;
			}
			if($sub){
				$switcher = "<span class='switcher expand more'>◇</span>";
			}else{
				$switcher = "<span class='switcher collapse'>◇</span>";
			}
			if(count($param)>0 and $param[0]){
				$ret .= "<li>$switcher <a href='".$param[0]."'>".$name."</a></li>";
			}else{
				$ret .= "<li>$switcher ".$name."</li>";
			}
			
			if($sub){
				$ret .= "<li class='submenu'>".self::gen($param[1], '', 1)."</li>";
			}
		}
		
		$ret .= "</ul>";
		return $ret;
	}
}